package com.ph.clouds.tracker.network;

import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * @Author yushuangjiang
 * @Time 2021/8/3 15:12
 * @Description：
 */
public class HttpTask implements Runnable {
    private IHttpRequest httpRequest;
    private IHttpListener httpListener;

    public  HttpTask(String requestInfo, Map<String,String> header, String url, IHttpRequest httpRequest, IHttpListener httpListener) {
        this.httpRequest = httpRequest;
        this.httpListener = httpListener;
        //设置url
        this.httpRequest.setUrl(url);
        //设置响应回调
        this.httpRequest.setHttpCallBack(httpListener);
        //设置请求参数
        if (requestInfo != null) {
            //字符串转byte数组
            try {
                this.httpRequest.setRequestData(requestInfo.getBytes("utf-8"),header);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }

    }

    @Override
    public void run() {
        httpRequest.execute();
    }
}
